using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;

namespace Soft1ApiDemo.Infrastructure.Filters
{
    public class CustomGlobalExceptionFilter: IAsyncExceptionFilter
    {
        public Task OnExceptionAsync(ExceptionContext context)
    {
        if (context.ExceptionHandled == false)
        {
            string msg = context.Exception.Message;
            context.Result = new ContentResult
            {
                Content = string.Format("该错误位于{0},错误内容是：{1}",context.ActionDescriptor.ToString(),context.Exception.ToString()),
                StatusCode = 200,
                ContentType = "text/html;charset=utf-8"
            };
        }
        context.ExceptionHandled = true; //异常已处理了

        return Task.CompletedTask;
    }
    }
}